<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:include page="../../common/header.jsp"/>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<script>
jQuery(document).ready(function() {    
	jQuery('#user_grid .group-checkable').change(function () {
        var set = jQuery(this).attr("data-set");
        var checked = jQuery(this).is(":checked");
        jQuery(set).each(function () {
            if (checked) {
                $(this).attr("checked", true);
            } else {
                $(this).attr("checked", false);
            }
        });
        jQuery.uniform.update(set);
    });
	
});

function toListPage(pageIndex){
	$("#list_form").attr("action","<%=request.getContextPath() %>/qrtz/job/list");
	$("#iDisplayStart").val(pageIndex);
	$("#list_form").submit();
}

function delJob(){
	var checkedboxs = $('input:checkbox[name=jobNames]:checked');
	if(checkedboxs.length>0){
		bootbox.dialog({
			message : "确定删除选项任务吗？",
			title : "删除任务",
			buttons : {
				confirm : {
					label : '<spring:message code="sure to delete"></spring:message>',
					className : "btn red btn-ok",
					callback : function() {
						$("#list_form").attr("action","<%=request.getContextPath() %>/qrtz/job/delete");
						$("#list_form").submit();
					}
				},
				cancel : {
					label : "<spring:message code="cancel"></spring:message>",
					className : "btn btn-danger"
				}
			}
		});
	}
	
}


function toEditPage(id){
	$("#list_form").attr("action","<%=request.getContextPath()%>/qrtz/job/form");
	$("#list_form").submit();
}

function resumeJob(){
	var checkedboxs = $('input:checkbox[name=jobNames]:checked');
	if(checkedboxs.length>0){
	bootbox.dialog({
		message : "确定启动所选任务吗？",
		title : "启动任务",
		buttons : {
			confirm : {
				label : "确定",
				className : "btn red btn-ok",
				callback : function() {
					$("#list_form").attr("action","<%=request.getContextPath()%>/qrtz/job/resume");
					$("#list_form").submit();
				}
			},
			cancel : {
				label : "<spring:message code="cancel"></spring:message>",
				className : "btn btn-danger"
			}
		}
	});
	}
}

function pauseJob(){
	var checkedboxs = $('input:checkbox[name=jobNames]:checked');
	if(checkedboxs.length>0){
	bootbox.dialog({
		message : "确定暂停所选任务吗？",
		title : "暂停任务",
		buttons : {
			confirm : {
				label : "确定",
				className : "btn red btn-ok",
				callback : function() {
					$("#list_form").attr("action","<%=request.getContextPath()%>/qrtz/job/pause");
					$("#list_form").submit();
				}
			},cancel : {
				label : "<spring:message code="cancel"></spring:message>",
				className : "btn btn-danger"
			}
		}
	});
	}
}

function execJob(){
	var checkedboxs = $('input:checkbox[name=jobNames]:checked');
	if(checkedboxs.length>0){
			bootbox.dialog({
				message : "确定立即执行所选任务吗？",
				title : "执行任务",
				buttons : {
					confirm : {
						label : "确定",
						className : "btn red btn-ok",
						callback : function() {
							$("#list_form").attr("action","<%=request.getContextPath()%>/qrtz/job/execute");
							$("#list_form").submit();
						}
					},cancel : {
						label : "<spring:message code="cancel"></spring:message>",
						className : "btn btn-danger"
					}
				}
			});
	}
}

function clearSearch(){
	$("#search_jobName").val("");
	$("#search_jobDesc").val("");
	$("#search_state").val("");
	$("#search_jobGroup").val("");
}


</script>

</head>
<body class="page-header-fixed page-full-width">

		<form id="list_form" action="<%=request.getContextPath() %>/qrtz/job/list" method="post">
		<input type="hidden" name="sorting_column_order" id="sorting_column_order" value="${list.orderBy }"/>
		<input type="hidden" name="sorting_asc_desc"  id="sorting_asc_desc" value="${list.sort}"/>
		<input type="hidden" name="id" id="hiddenId"></input>
		<input type="hidden" name="iDisplayStart" id="iDisplayStart" value=${list.currentPage } />
		<input type="hidden" name="token" value="${token}"></input>
		<div class="page-content">


			<!-- BEGIN PAGE CONTAINER-->

			<div class="container-fluid">

				<!-- BEGIN PAGE HEADER-->

				<div class="row-fluid">

					<div class="span12">
						
					
						<h3 class="page-title">

							<!--系统用户管理 <small>欢迎您，admin!</small> -->

						</h3> 

						<ul class="breadcrumb">

							<li>

								<i class="icon-home"></i>

								<a href="index.html">Home</a> 

								<i class="icon-angle-right"></i>

							</li>

							<li>

								<a href="#">系统管理</a>

								<i class="icon-angle-right"></i>

							</li>

							<li><a href="#">定时任务</a></li>

						</ul>

						

					</div>

				</div>

				<!-- END PAGE HEADER-->

				<!-- BEGIN PAGE CONTENT-->

				

				<div class="row-fluid">
							<!-- BEGIN EXAMPLE TABLE PORTLET-->

						<!--<div class="portlet box light-grey">

							<div class="portlet-title">

								<div class="caption"><i class="icon-globe"></i>系统用户列表</div>

								<div class="tools">

									<a href="javascript:;" class="collapse"></a>

									<a href="#portlet-config" data-toggle="modal" class="config"></a>

									<a href="javascript:;" class="reload"></a>

									<a href="javascript:;" class="remove"></a>

								</div>

							</div>  -->

							<div class="portlet-body">
								<c:if test="${success!=null && success==false}">
									<div class="alert alert-error">
										<button class="close" data-dismiss="alert"></button>
										${result_info}
									</div>
								</c:if>
								<c:if test="${success==true}">
									<div class="alert alert-success">
										<button class="close" data-dismiss="alert"></button>
										${result_info}
									</div>
								</c:if>
								<div class="clearfix">

									<p class="pull-left">
										
										<a href="#" onclick="toEditPage(null);" class="btn blue" >
										新增任务<i class="icon-plus"></i>
										</a>
										|
										<a href="#" onclick="resumeJob();" class="btn blue" >
										启动任务
										</a>
										
										<a href="#" onclick="pauseJob();" class="btn red" >
										暂停任务
										</a>
										|
										
										
										<a href="#" onclick="delJob();" class="btn red" >
										删除任务
										</a>
										
										|
										<a href="#" onclick="execJob();" class="btn red" >
										立即执行任务
										</a>
									</p>

									

								</div>
								
								
						

								
										
							<div class="portlet">
								<!--<div class="portlet-title">

								<div class="caption"><i class="icon-search"></i>查询条件</div>
								</div>  -->
								
								<div class="portlet-body">
											<table class="table" style="min-width: 880px">
												<tbody>
												<tr>
													
													<td style="text-align: right">任务名称 : </td>
													<td><input type="text" id="search_jobName" name="jobName" value="${jobName }"/></td>
													<td style="text-align: right">任务描述 : </td>
													<td><input type="text" id="search_jobDesc" name="jobDesc" value="${jobDesc }"/></td>
													<td style="text-align: right"></td>
													<td></td>
													
												</tr>
												<tr>
													<td style="text-align: right">触发状态 : </td>
													<td>
														<select id="search_state" class="chosen-with-diselect span6" tabindex="-1" name="state" style="width: 220px;">
															<option value=""></option>
															<option <c:if test="${state=='PAUSED'}">selected="selected"</c:if> value="PAUSED">暂停中</option>
															<option <c:if test="${state=='WAITING'}">selected="selected"</c:if> value="WAITING">等待中</option>
															<option <c:if test="${state=='ACQUIRED'}">selected="selected"</c:if> value="ACQUIRED">正常执行中</option>
															<option <c:if test="${state=='BLOCKED'}">selected="selected"</c:if> value="BLOCKED">运行阻塞</option>
															<option <c:if test="${state=='COMPLETE'}">selected="selected"</c:if> value="COMPLETE">运行完成</option>
															<option <c:if test="${state=='ERROR'}">selected="selected"</c:if> value="ERROR">运行错误</option>
														</select>
													</td>
													<td style="text-align: right">任务分组 : </td>
													<td>
														<select id="search_jobGroup"  class="chosen-with-diselect span6" tabindex="-1" name="jobGroup" style="width: 220px;">
															<option value=""></option>
															<c:forEach var="g" items="${select_groups}">
																<option <c:if test="${jobGroup==g.jobGroup}">selected="selected"</c:if> value="${g.jobGroup }">${g.jobGroup }</option>
															</c:forEach>
														</select>
													</td>
														
													<td style="text-align: left" colspan="2">
														<a href="#" onclick="toListPage(1);" class="btn blue" >查询</a>
														<a href="#" onclick="clearSearch();" class="btn red">清除</a>
													</td>
												</tr>
												</tbody>
											</table>
								</div>
							</div>
								

								<table class="table table-striped table-bordered table-hover" id="user_grid">

									<thead>

										<tr>
											<th style="width:8px;"><input type="checkbox" class="group-checkable" data-set="#user_grid .checkboxes" /></th>
											<th width="80">状态</th>
											<!--<th width="80">触发器名称</th>
											<th>分组</th>-->
											<th>任务名称</th>
											<th>分组</th>
											<th>任务描述</th>
											<!--  <th>任务类</th>-->
											<th>表达式</th>
											<th>开始时间</th>
											<th>结束时间</th>
											<th>上次运行时间</th>
											<th>下次运行时间</th>
										</tr>

									</thead>
									<tbody>
										<c:forEach items="${list.resultList}" var="item" varStatus="status">
										
									
										<tr class="odd gradeX">
											<td><input type="checkbox" class="checkboxes" name="jobNames" value="${item.jobName}-${item.triggerGroup}" />
												
											</td>
											<td>${item.triggerState }</td>
											<!--<td>${item.triggerName }</td>
											<td>${item.triggerGroup }</td>-->
											<td>${item.jobName }</td>
											<td>${item.jobGroup }</td>
											<td>${item.description }</td>
											<!--<td>${item.jobClassName }</td>-->
											<td>${item.cronExpression }</td>
											<td>${item.startTime }</td>
											<td>${item.endTime }</td>
											<td>${item.prevFireTime }</td>
											<td>${item.nextFireTime }</td>
										</tr>
										</c:forEach>
									</tbody>
									
								</table>
								<!-- 分页 -->
								<c:if test="${list.totalPages>1}">
									<div class="pagination" style="float:right">
										<ul>
											<li><a href="javascript:void();"><spring:message
														code="total"></spring:message>：${list.totalRows}</a></li>
											<li <c:if test="${list.currentPage==1}">class="disabled"</c:if>>
												<c:if test="${list.currentPage>1}">
													<a href="javascript:toListPage(${list.currentPage-1});"><spring:message
														code="previous page"></spring:message></a>
												</c:if>
												<c:if test="${list.currentPage==1}">
													<a href="#"><spring:message
														code="previous page"></spring:message></a>
												</c:if>
											</li>
											<c:forEach begin="1" end="${list.totalPages}" var="item">
											<c:if test="${item < 4 || item==list.currentPage || item==list.currentPage+1 || item==list.currentPage+2 || item + 3 > list.totalPages }">
											<li <c:if test="${list.currentPage==item }">class="active"</c:if>><a href="javascript:toListPage(${item});">${item}</a></li></c:if>
											</c:forEach>
											<li <c:if test="${list.currentPage==list.totalPages}">class="disabled"</c:if>>
												<c:if test="${list.currentPage==list.totalPages}">
													<a href="#"><spring:message
														code="next page"></spring:message></a>
												</c:if>
												<c:if test="${list.currentPage!=list.totalPages}">
													<a href="javascript:toListPage(${list.currentPage+1})"><spring:message
														code="next page"></spring:message> </a>
												</c:if>
											</li>
										</ul>
									</div>
								</c:if>
							</div>

						<!--  </div>-->

						</div>
			</div>


		</div>
		
		</form>
		

	


</body>